package com.mangoerp.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.*;

/**
 * @author yincb
 * @title: UserController
 * @date 2021/12/617:26
 */
@RestController
public class UserController {

    private Map<Integer,User> users = new HashMap<>();

    @GetMapping("getUser/{id}")
    public User getUser(@PathVariable("id")Integer id) {
        return users.get(id);
    }

    @GetMapping("getAllUser")
    public List<User> getAllUser() {
        ArrayList<User> result = new ArrayList<>();
        users.values().stream().forEach(user -> result.add(user));
        return result;
    }



    @PostConstruct
    public void init(){
        users.put(1,User.builder().id(1).name("Tom").addr("BJ").build());
        users.put(2,User.builder().id(2).name("Nice").addr("AH").build());
        users.put(3,User.builder().id(3).name("Jack").addr("NJ").build());
    }
}
